<?php

App::uses('Right', 'Model');


class UserRightsTemplate extends AppModel {
    
    //define model name
    var $name = 'UserRightsTemplate';
    
    //define model schema
    var $schema = array(
        'id'                    => array(
            'type' => 'date'
        ),
        'name'                  => array(
            'type' => 'date'
        ),
        'rights'                => array(
            'type' => 'date'
        ),
        'description'           => array(
            'type' => 'date'
        ),
        'deleted' => array(
            'type' => 'int'
        ),
        'deletedOn' => array(
            'type' => 'date'
        )
    );
    
    public function __construct() {
        parent::__construct();
        
        $this->Right = new Right();
        
    }
    
    public function createDefaultTemplate($admin = null,$user = null) {
        
        if ($admin == null) {
            return array();
        }
        
        $definedRights  = Constants::$rights;
        $editableRights = $this->Right->getRights($admin);
        $databaseRights = $this->Right->getRights($user);
        
        
        foreach ($definedRights as $domain) {
            foreach ($domain as $right => &$properties) {
                
                $properties = array('test');
                //if (in_array($rigs, $haystack))
            }
        }
        
        
        foreach($editableRights as $right) {
            
        }
        
        foreach ($databaseRights as $right) {
            
        }
        
        $this->log($definedRights,'mylog');
        $this->log($editableRights,'mylog');
        $this->log($databaseRights,'mylog');
        
        
        return $definedRights;
    }
    
    public function getTemplates($user = null) {
        
        return array();
        
        /*$templates = array();
        return $templates;
        if ($user == null) {
            return $templates;
        }
        
        $dbTemplates = $this->find('all',array('conditions' => array('user_id' => $user,'deletedOn' => null)));
        foreach($dbTemplates as $template) {
            
            $rights = explode('|',$template['UserRightsTemplate']['rights']);
            
            
        }
        
        return $available;*/
        
    }

}

?>